LearningStoreJob.DemandRight Method (string, IDictionary<string,object>)

Demand a right. When the job is executed, the job will be aborted unless the current user has the specified right.

Parent Type: LearningStoreJob

Namespace: Microsoft.LearningComponents.Storage

Assembly: Microsoft.LearningComponents.Storage.dll

Syntax
C#

public void DemandRight (
string rightName,
IDictionary<string,object> parameterValues

)

Parameters

rightName

The name of the right to demand

parameterValues

Extra information used to determine if the current user has the right, or null if no extra information is provided. The key is the parameter name, and the value is the value for the parameter. If a value for a particular parameter isn't provided, a value of null is assumed. See the documentation for the right specified by rightName for a list of parameters accepted by that right.

Exceptions
Exception type Condition
ArgumentNullException

rightName is a null reference.

System.InvalidOperationException

The right in rightName doesn't exist in the store, a parameter name passed in parameterValues doesn't exist on the right, or a parameter value passed in parameterValues is not a valid value for the corresponding parameter.

Remarks

Steps required to demand a right:

parameterValues should contain one entry for each parameter that should have a non-null value. The value type differs depending on the type of the property on the item. See LearningStoreQuery.SetParameter for more details.

Example

The following code demands that the user has the "ReadPackageRight" for the package specified by "packageId". If the user has the right, then the location of the package is retrieved. If the user doesn't have the right, then an exception is thrown.

C#
// Create a job
LearningStoreJob job = store.CreateJob();
 
// Create the parameters for the demand
Dictionary<string,object> parameterValues = new Dictionary<string,object>();
parameterValues["PackageId"] = packageId;
 
// Demand the right
job.DemandRight("ReadPackageRight", parameterValues);
 
// Create the query that will return the location
LearningStoreQuery query = store.CreateQuery("PackageItem");
query.AddColumn("Location");
query.AddCondition("Id", LearningStoreConditionOperator.Equal, packageId);
job.PerformQuery(query);
 
// Execute the job
DataTable result = job.Execute<DataTable>();